package cn.huixh.blindbox.aop;

import cn.huixh.blindbox.service.TokenService;
import cn.huixh.blindbox.utils.JoinPointUtil;
import cn.hutool.jwt.JWTException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author huixh
 * @version 1.0
 * @date 2022/5/13 13:42
 */

@Slf4j
@Aspect
@Component
@RequiredArgsConstructor
public class TokenAspect {

    final TokenService tokenService;

    final JoinPointUtil joinPointUtil;

    @Pointcut("@annotation(cn.huixh.blindbox.annotation.TokenVerify)")
    public void tokenPointCut() {
    }

    /**
     * token 验证
     *
     * @param joinPoint joinPoint
     * @throws JWTException jwt 验证异常
     */
    //@Before("tokenPointCut()")
    public void doBefore(JoinPoint joinPoint) throws JWTException {

        String token = joinPointUtil.getParamByName(joinPoint, "token", String.class);
        //tokenService.tokenVerify(token);
    }
}
